package com.example.controller;

import com.example.common.PageResult;
import com.example.common.Result;
import com.example.dto.WSCheckDto;
import com.example.entity.WSCheck;
import com.example.service.WSCheckService;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Delete;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@Slf4j
@RestController
@RequestMapping("/admin/wscheck")
public class WSCheckController {
    @Autowired
    private WSCheckService wsCheckService;

    @GetMapping("/page")
    public Result<PageResult> page(WSCheckDto wsCheckDto) {
        log.info("卫生检查数据查询...", wsCheckDto);
        PageResult page = wsCheckService.page(wsCheckDto);
        return Result.success(page);
    }

    @PostMapping("/add")
    public Result add(@RequestBody WSCheck wsCheck) {
        wsCheckService.add(wsCheck);
        return Result.success();
    }

    @DeleteMapping("{dno}")
    public Result deleteByDno(@PathVariable String dno){
        wsCheckService.deleteByDno(dno);
        return Result.success();
    }

    @PutMapping
    public Result update(@RequestBody WSCheck wsCheck){
        log.info("宿舍卫生检查信息更新{}",wsCheck);
        wsCheckService.update(wsCheck);
        return Result.success();
    }
}
